package svc

import (
	"mall/service/backend/common/websocket"
	"mall/service/user/api/internal/config"
	"mall/service/user/rpc/userclient"

	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config config.Config
	Hub    *websocket.Hub

	SetUidToCtxMiddleware rest.Middleware

	UserRpc userclient.User
}

func NewServiceContext(c config.Config) *ServiceContext {
	hub := websocket.NewHub()
	go hub.Run()

	return &ServiceContext{
		Config:  c,
		Hub:     hub,
		UserRpc: userclient.NewUser(zrpc.MustNewClient(c.UserRpc)),
	}
}
